package portal.utils;

public class Picker {
	
	// method for single object
	public static String[][] picker(PortalObject object){
		PortalObject[] singleObject = {object};	
		return picker(singleObject);
	}
	
	public static String[][] picker(PortalObject[] object){
		// calculate the length of the array
		int lengthArray = 0;
		for (int i=0;i<object.length;i++){
			for (int j=0;j<object[i].getAllValuesForAttributes().size(); j++)
				lengthArray+=object[i].getAllValuesForAttributes().get(object[i].getAllAttributes()[j]).length;
		}
		
		String[][] answer = new String[lengthArray][4];
		int rows = 0, countRowsForObject = 0;
		
		for (int i=0;i<object.length;i++){
			rows += countRowsForObject;
			countRowsForObject = 0;
			for (int j=0;j<object[i].getAllValuesForAttributes().size();j++){
				for (int k=0;k<object[i].getAllValuesForAttributes().get(object[i].getAllAttributes()[j]).length;k++){
					answer[rows+countRowsForObject][0] = object[i].getID();
					answer[rows+countRowsForObject][1] = object[i].getType();
					answer[rows+countRowsForObject][2] = object[i].getAllAttributes()[j];
					answer[rows+countRowsForObject][3] = object[i].getAllValuesForAttributes().get(object[i].getAllAttributes()[j])[k];
					countRowsForObject++;
				}
			}
		}	
		return answer;
	}
}
